/*!
* 
* Copyright (c) 2009 by yuqiang @ vcedu
* 
* Description:
*		This file contains the video interface which would be used outside the lib
*
* ChangeLog:
*		$Date$	$Rev$	$Author$
* 
*/	

#include "stdafx.h"

#include "ivideo.h"

#include <rtpipv4address.h>
#include <log4cpp/Category.hh>

#include "videosession.h"

static log4cpp::Category& Logger = log4cpp::Category::getInstance(__Module__Name+std::string(".ivideo"));

// global variance, we should have only one videSession
static VideoSession __videoSession;
static VideoSessionParams __videoParams;

extern "C"{

	LIBRTP_API void librtp_video_param_init(struct VideoParam *pParam){
		if(NULL == pParam){
			Logger.error(DEBUG_MSG("pParam is a Null Pointer"));
		}		
		pParam->m_devNum = 0;
		pParam->m_width = 320;
		pParam->m_height = 240;
		pParam->m_frameRate = 25.0;
		pParam->m_portbase = 6100;
		pParam->m_acceptOwnPackets = true;
		pParam->m_bandwidth = 200000;
	}

	LIBRTP_API bool librtp_video_init(struct VideoParam *pParam){

		if(NULL == pParam){
			Logger.error(DEBUG_MSG("pParam is a Null Pointer"));
		}

		__videoParams.setPortbase(pParam->m_portbase);
		__videoParams.setAcceptOwnPackets(pParam->m_acceptOwnPackets);
		__videoParams.setDevice(pParam->m_devNum);
		__videoParams.setFrameRate(pParam->m_frameRate);
		__videoParams.setWidth(pParam->m_width);
		__videoParams.setHeight(pParam->m_height);

		return __videoSession.init(&__videoParams);
	}

	LIBRTP_API bool librtp_video_close(){
		return __videoSession.destroy();
	}

	LIBRTP_API bool librtp_video_addDestination(unsigned char ipAddr[4],unsigned int port){
		return __videoSession.addDestination(RTPIPv4Address(ipAddr,port));
	}

	LIBRTP_API bool librtp_video_deleteDestination(unsigned char ipAddr[4],unsigned int port){
		return __videoSession.deleteDestination(RTPIPv4Address(ipAddr,port));
	}

	LIBRTP_API bool librtp_video_clearDestinations(){
		return __videoSession.clearDestinations();
	}

	LIBRTP_API bool librtp_video_setReceiveMode(ReceiveMode mode){
		return __videoSession.setReceiveMode(static_cast<RTPTransmitter::ReceiveMode>(mode));
	}

	LIBRTP_API bool librtp_video_addToIgnoreList(unsigned char ipAddr[4],unsigned int port){
		return __videoSession.addToIgnoreList(RTPIPv4Address(ipAddr,port));
	}

	LIBRTP_API bool librtp_video_deleteFromIgnoreList(unsigned char ipAddr[4],unsigned int port){
		return __videoSession.deleteFromIgnoreList(RTPIPv4Address(ipAddr,port));
	}

	LIBRTP_API bool librtp_video_clearIgnoreList(){
		return __videoSession.clearIgnoreList();
	}

	LIBRTP_API bool librtp_video_addToAcceptList(unsigned char ipAddr[4],unsigned int port){
		return __videoSession.addToAcceptList(RTPIPv4Address(ipAddr,port));
	}

	LIBRTP_API bool librtp_video_deleteFromAcceptList(unsigned char ipAddr[4],unsigned int port){
		return __videoSession.deleteFromAcceptList(RTPIPv4Address(ipAddr,port));
	}

	LIBRTP_API bool librtp_video_clearAcceptList(){
		return __videoSession.clearAcceptList();
	}

	LIBRTP_API bool librtp_video_startSendChain(){
		return __videoSession.startSendChain();
	}

	LIBRTP_API bool librtp_video_stopSendChain(){
		return __videoSession.stopSendChain();
	}

	LIBRTP_API bool librtp_video_startReceiveChain(){
		return __videoSession.startReceiveChain();
	}

	LIBRTP_API bool librtp_video_stopReceiveChain(){
		return __videoSession.stopReceiveChain();
	}

	LIBRTP_API bool librtp_video_startSession(){
		return __videoSession.startSession();
	}

	LIBRTP_API bool librtp_video_stopSession(){
		return __videoSession.stopSession();
	}

	LIBRTP_API bool librtp_video_isInit(){
		return __videoSession.isInit();
	}

	LIBRTP_API bool librtp_video_isSessionRunning(){
		return __videoSession.isSessionRunning();
	}

	LIBRTP_API bool librtp_video_isSendRunning(){
		return __videoSession.isSendRunning();
	}

	LIBRTP_API bool librtp_video_isReceiveRunning(){
		return __videoSession.isReceiveRunning();
	}
};
